package com.cookie; /**
 * @author wzm
 * @create 2023-05-10 14:47
 */

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/cookie04")
public class CookieServlet04 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Cookie cookie = new Cookie("pwd","张三");
        //设置Cookie的存活时间 存活一个星期
        //cookie.setMaxAge(604800);
        cookie.setMaxAge(60*60*24*7);
        response.addCookie(cookie);

    }
}
